﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Rison.DataAccess.Common;
using Rison.DBHelper;

namespace Rison.DataAccess.Data.ZP
{
    public sealed class SelfExaminationDB : DataAccessBase
    {
         public SelfExaminationDB()
            : base()
        {
        }

         public SelfExaminationDB(DbBaseHelper dbTransaction)
            : base(dbTransaction)
        {
        }

        protected override string tableName
        {
            get { return "SelfExamination"; }
        }

        protected override string IdentityFieldName
        {
            get { return "ID"; }
        }

        //protected override string OrderBy
        //{
        //    get { return "UserId"; }
        //}
        public DataRow GetID(string departid, int year)
        {
            return base.ExecuteSqlToDataRow("select ID from SelfExamination where departid='" + departid + "' and year ='" + year + "'");
        }

        public DataRow GetInformation(string id)
        {
            return base.ExecuteSqlToDataRow("select ID from SelfExamination where id='" + id + "'");
        }

        public DataRow GetInformation(string departid, int year)
        {
            return base.ExecuteSqlToDataRow("select * from SelfExamination where departid='" + departid + "' and year ='" + year + "'");
        }

        #region "子表信息"

        public DataSet GetSubInfoByParentID(string tableName, string parentId)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat("select * from {0} where ExamID='{1}' order by ordername", tableName,parentId);
            return base.ExecuteSql(sql.ToString(), "GetSubInfoByParentID");
        }
    
        /// <summary>
        /// 删除子表信息。
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public int DeleteSubInfobyParentId(string tableName,string parentId)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat("delete from {0} where examid='{1}'", tableName, parentId.ToString());

            return base.ExecuteNonSql(sql.ToString());
        }
             

        /// <summary>
        /// 插入子表信息。
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public int InsertSubInfobyParentId(string tableName, string Param)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat("insert into {0} values ({1})", tableName, Param);

            return base.ExecuteNonSql(sql.ToString());
        }

        #endregion
    }
}
